﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Mock1G3.DataAccess
{
    public class WithDrawAccess
    {
        private static decimal minValue = 50000;

        private static decimal maxValue = 15000000;

        //Check balance
        public static decimal GetBalance(int accountID)
        {
            return DataAccess.ExeStoredToDecimal("[dbo].[SP_GetBalance]", "@AccountID", accountID);
        }

        //Check amount with balance
        public static bool CheckValidAmountWithBalance(decimal amount, int accountID)
        {
            if (amount <= GetBalance(accountID)) 
                return true;
            return false;
        }

        //Check amount with min-max values
        public static bool CheckValidAmountWithMinValue(decimal amount)
        {
            if (amount >= minValue)
                return true;
            return false;
        }
        public static bool CheckValidAmountWithMaxValue(decimal amount)
        {
            if (amount <= maxValue)
                return true;
            return false;
        }

        //Check amount % 50000 is true
        public static bool CheckAmountDivide(decimal amount)
        {
            if ((amount % 50000) == 0)
                return true;
            return false;
        }
        //Get limit withdraw
        public static decimal GetLimitWithDraw()
        {
            return DataAccess.ExeStoredToDecimal("[dbo].[SP_GetWithDrawLimit]");
        }

        //Get withdraw in a day

        public static decimal GetAmount(int accountID)
        {
            return DataAccess.ExeStoredToDecimal("[SP_GetWithDrawInADay]", "@AccountID", accountID);
        }

        //Check validate withdraw over limit

        public static bool CheckOverDrawLimit(decimal amount, int accountID)
        {
            if (amount <= (GetLimitWithDraw() - GetAmount(accountID))) return true;
            return false;
        }
        public static bool WithDraw(decimal amount, int accountID, int ATMID, string cardNo)
        {
            try
            {
                DataAccess.ExeStoredWithParamNon("[dbo].[SP_WithDraw]", "@amount", amount, "@AccountID", accountID, "@ATMID", ATMID, "@CardNo", cardNo);
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}